package com.eascs.archive_query.controller;

import java.util.List;

import javax.inject.Inject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.admin.api.form.O2oAfterLoanForm;
import com.eascs.admin.common.controller.BaseMasterViewController;
import com.eascs.admin.o2o.credit.service.CreditReportService;
import com.eascs.afterloan.service.O2oAfterService;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.common.util.UrlUtil;
import com.eascs.crm.common.service.ICustomerInfoService;
import com.eascs.datalist.service.O2oDataListService;
import com.eascs.loan.service.O2oPaymentsService;
import com.eascs.site.view.ViewContext;
import com.eascs.tag.MenuTag;
import com.eascs.workflow.common.entity.sys.ActOrgEntity;
import com.eascs.workflow.common.service.sys.SysOrgService;

@Controller
@RequestMapping("/archive_query")
public class Archive_QueryController extends BaseMasterViewController {
	private final Logger logger = LoggerFactory.getLogger(Archive_QueryController.class);

	@Reference
	SysOrgService sysOrgService;
	@Reference
	ICustomerInfoService iCustomerInfoService;

	@Autowired
	CreditReportService creditReportService;

	@Inject
	O2oPaymentsService o2oPaymentsService;

	@Value("${o2o.admin.iframe.domain}")
	private String domain;

	@Autowired
	O2oAfterService service;

	@Autowired
	O2oDataListService o2oDataListService;
	@Value("${o2o.admin.excelExport.AfterLoan}")
	private String excelExportAfterLoan;

	@Value("${o2o.admin.afterloan.oldUrl}")
	private String afterloanOldUrl;
	public void preHandle() {
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "ArchiveQuery");
	}

	/**
	 * 归档查询
	 * 
	 * @param vo
	 * @return
	 */
	@RequestMapping("/index")
	public String index(O2oAfterLoanForm vo) {
		// vo.setPageSize(10);
		// String o2ourl="/archive_query/index";
		String o2ourl = "/rarchive_query/o2o";
		List<ActOrgEntity> orgProvince = sysOrgService.getOrgProvince();// 省区
		ViewContext.put("ActOrgEntitys", orgProvince);
		if (vo != null) {
			String billCode = vo.getBillCode() == null ? "" : vo.getBillCode();
			String loanUserName = vo.getLoanUserName() == null ? "" : vo.getLoanUserName();// 将userFullName存入loanUserName
			String loanType = vo.getLoanType() == null ? "" : vo.getLoanType();
			String bankLoan = vo.getBankLoan() == null ? "" : vo.getBankLoan();
			String operName = vo.getOperName() == null ? "" : vo.getOperName();
			String loanDateStart = vo.getLoanDateStart() == null ? null : vo.getLoanDateStart();
			String loanDateEnd = vo.getLoanDateEnd() == null ? null : vo.getLoanDateEnd();
			String repaystatus = vo.getRepaystatus() == null ? "" : vo.getRepaystatus();
			String dateDueStart = vo.getDateDueStart() == null ? null : vo.getDateDueStart();
			String dateDueEnd = vo.getDateDueEnd() == null ? null : vo.getDateDueEnd();
			o2ourl = UrlUtil.appendUrl(o2ourl, "billCode", billCode);
			o2ourl = UrlUtil.appendUrl(o2ourl, "loanUserName", loanUserName);
			o2ourl = UrlUtil.appendUrl(o2ourl, "loanType", loanType);
			o2ourl = UrlUtil.appendUrl(o2ourl, "bankLoan", bankLoan);
			o2ourl = UrlUtil.appendUrl(o2ourl, "operName", operName);
			o2ourl = UrlUtil.appendUrl(o2ourl, "loanDateStart", loanDateStart);
			o2ourl = UrlUtil.appendUrl(o2ourl, "loanDateEnd", loanDateEnd);
			o2ourl = UrlUtil.appendUrl(o2ourl, "repaystatus", repaystatus);
			o2ourl = UrlUtil.appendUrl(o2ourl, "dateDueStart", dateDueStart);
			o2ourl = UrlUtil.appendUrl(o2ourl, "dateDueEnd", dateDueEnd);
			o2ourl = o2ourl + "&o2oIndex=";// ArchivequeryForm中索引页 private int
											// pageSize;
			// private int o2oIndex;
		} else {
			o2ourl = o2ourl + "?o2oIndex=";
		}
		ViewContext.put("o2ourl", o2ourl);
		ViewContext.put("vo", vo);
		return "archive_query/index";

	}

//	@RequestMapping(value = "/loanDetail", method = RequestMethod.GET)
//	public String showDetail(ShowDetailForm showDetailForm) {
//		return "redirect:/loanDetail?billCode=" + showDetailForm.getBillCode();
//	}
}
